package cn.xfdzx.android.apps.shop.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.HomeSearchXFDGoodBeen;

public class MarketRightRecyerAdapter extends BaseQuickAdapter<HomeSearchXFDGoodBeen.DataBean, BaseViewHolder> {
    RoundedCorners roundedCorners;
    RequestOptions options;

    public MarketRightRecyerAdapter() {
        super(R.layout.adapter_market_right);
        roundedCorners = new RoundedCorners(20);
        options = RequestOptions.bitmapTransform(roundedCorners).override(200, 200);
        options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                .error(R.drawable.icon_defult);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeSearchXFDGoodBeen.DataBean item) {

        helper.setText(R.id.tv_title_name, item.getTitle())
                .setText(R.id.tv_weight_preice, "约" + item.getUnit_price_per_jin() + "/斤")
                .setText(R.id.tv_all_weight, "毛重: " + item.getGoods_weight() + "斤");


        Glide.with(mContext).load(item.getThumb()).apply(options.transform(new CenterCrop(), roundedCorners)).into((ImageView) helper.getView(R.id.iv_image));


        //购物车数量
        TextView tv_num = helper.getView(R.id.tv_car_num);
        if (item.getCart_num() == 0) {
            tv_num.setVisibility(View.GONE);
        } else {
            tv_num.setVisibility(View.VISIBLE);
        }
        tv_num.setText(item.getCart_num() + "");


        //判断当前商品是否有折扣，无折扣取原价
        if (item.getDiscountprice().equals("0.00")) {
            helper.setText(R.id.tv_all_price, "¥" + item.getMarketprice() + "/" + item.getUnit());
        } else {
            helper.setText(R.id.tv_all_price, "¥" + item.getDiscountprice() + "/" + item.getUnit());
        }


        helper.addOnClickListener(R.id.iv_add_car);//添加购物车点击事件

    }
}
